package edu.nakan.sortvietnamesename;

/**
 * @author PHUNG Nam Can - NakanPhung
 * @mail cank56hua@gmail.com
 * @date Jul 27, 2013 9:25:20 PM
 * @project SortVietnameseName
 * @file SortVietnameseName.java
 */

public class SortVietnameseName {

	public static void main(String[] args) {
		String[] fullname = { "Nguyen Van Á","Phung Van A", "Nguyen Canh Ân", "Le van B",
				"Ho van C", "Nguyen Van" };
		String[] name = new String[100];
		for(int i = 0; i<fullname.length;i++){
			
			String[] names = fullname[i].trim().split(" ");
			name[i] = new String( names[names.length-1]);
			
		}
		for (int i = 0; i < fullname.length-1; i++) {
			
			for (int j = i + 1; j < fullname.length; j++) {
				if (name[i].compareTo(name[j]) >0) {
					String temp;
					temp = fullname[i];
					fullname[i] = fullname[j];
					fullname[j] = temp;
				}
			}// end for (j)
		} // end for (i)
		
		for(int i=0; i<fullname.length;i++){
			System.out.println(fullname[i]);
		}
		
		

	}
}
